//
//  NetWorkTaskHandle.m
//  UI19_DouBan
//
//  Created by dllo on 15/11/20.
//  Copyright (c) 2015年 CJ. All rights reserved.
//

#import "NetWorkTaskHandle.h"

@implementation NetWorkTaskHandle

+(void)sendTask:(NSString *)url withBody:(NSData *)body withResult:(void (^)(id))block {
    NSURLSession *senssion = [NSURLSession sharedSession];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:body];
   NSURLSessionTask *task = [senssion dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
       if (!error) {
           id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
           block(result);
       }
   }];
    [task resume];
}

+(void)sendTask:(NSString *)urlString withResult:(void (^)(id result))block{

     NSURL *url = [NSURL URLWithString:urlString];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (!error) {
            id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            block(result);
        }
    }];

    [task resume];
}
@end
